startStates("STATE","cGame");

addState("INIT");
addState("LOGO");
addState("COPYRIGHT");
addState("LOADING");
addState("SPLASH");
addState("MAIN_MENU");

endStates();

##################

sub startStates
{
	open(outfile, ">".$_[0].".java");
	print outfile "public class ".$_[0]."\n{\n";
	$gameClass = $_[1];
	@states=();
}

sub endStates()
{
	print outfile "\n\t//--- States ---\n";
	$currentState = 0;

	foreach $st (@states)
	{
		print outfile "\tpublic static final int ".$st." = ".$currentState.";\n";
		$currentState++;
	}
	print outfile "\tpublic static final int LAST_STATE = ".$currentState.";\n";

	print outfile "\n\t//--- StateMachine ---\n";
	print outfile "\tpublic static final void update(int state)\n\t{\n";
	print outfile "\t\tswitch(state)\n\t\t{\n";

	foreach $st (@states)
	{
		print outfile "\t\tcase ".$st.":\n";
		print outfile "\t\t\t".$gameClass.".doState_".$st."();\n";
		print outfile "\t\t\tbreak;\n\n";
	}
	
	print outfile "\t\t}\n";
	print outfile "\t}\n";

	print outfile "\n\t//--- Names ---\n";
	print outfile "\tpublic static final String[] stateNames=\n\t\t{\n";
	foreach $st (@states)
	{
		print outfile "\t\t\t\"".$st."\",\n";
	}
	print outfile "\t\t\t\"LAST_STATE\"\n";
	print outfile "\t\t};\n";
	
	close(outfile);
}

sub addState
{
	@states = (@states, $_[0]);
}


